package com.example.myservice;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private static final String TAG = "Myservice MainActivity";
    private Button btn_start;
    private Button btn_stop;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        btn_start = findViewById(R.id.btn_start_service);
        btn_stop = findViewById(R.id.btn_stop_service);

        btn_start.setOnClickListener(this);
        btn_stop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_start_service:
                Log.e(TAG, "onClick: " + "btn_start_service");
                Intent startservice = new Intent(MainActivity.this,Myservice.class);
                startService(startservice);
                break;
            case R.id.btn_stop_service:
                Log.e(TAG, "onClick: " + "btn_stop_service");
                Intent stopservice = new Intent(MainActivity.this,Myservice.class);
                stopService(stopservice);
                break;
            default:
                break;
        }
    }
}